/**
 * 
 */
package com.wy2.generator.database.entity;

import java.io.Serializable;

import cn.xo68.core.util.StringTools;
import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * 数据库原始字段结构
 * @author nnsword
 * @date 2017-12-11 23:41:45
 *
 */
public class DatabaseColumn extends DatabaseElement implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	private DatabaseTable table;
	
	
	/**
	 * The java.sql.Types type
	 */
	private int sqlType;

	/**
	 * The sql typename. provided by JDBC driver
	 */
	private String sqlTypeName;

	/**
	 * The name of the column
	 */
	private String sqlName;

	/**
	 * True if the column is a primary key
	 */
	private boolean pk;

	/**
	 * @todo-javadoc Describe the column
	 */
	private int size;

	/**
	 * @todo-javadoc Describe the column
	 */
	private int decimalDigits;

	/**
	 * True if the column is nullable
	 */
	private boolean nullable;

	/**
	 * True if the column is indexed
	 */
	private boolean indexed;

	/**
	 * True if the column is unique
	 */
	private boolean unique;

	/**
	 * Null if the DB reports no default value
	 */
	private String defaultValue;
	
	/**
	 * The comments of column
	 */
	private String remarks;
	
	private boolean autoIncrement;
	private boolean generatedColumn;
	
	private String fullJavaType;
	private String javaProperty;
	
	

	/**
	 * 
	 */
	public DatabaseColumn(DatabaseTable table) {
		super();
		this.table=table;
	}
	public DatabaseColumn() {
        super();
    }
	
	@JsonIgnore
	public DatabaseTable getTable() {
        return table;
    }

    public void setTable(DatabaseTable table) {
        this.table = table;
    }

    /**
	 * @return the sqlType
	 */
	public int getSqlType() {
		return sqlType;
	}

	/**
	 * @param sqlType the sqlType to set
	 */
	public void setSqlType(int sqlType) {
		this.sqlType = sqlType;
	}

	/**
	 * @return the sqlTypeName
	 */
	public String getSqlTypeName() {
		return sqlTypeName;
	}

	/**
	 * @param sqlTypeName the sqlTypeName to set
	 */
	public void setSqlTypeName(String sqlTypeName) {
		this.sqlTypeName = sqlTypeName;
	}

	/**
	 * @return the sqlName
	 */
	public String getSqlName() {
		return sqlName;
	}

	/**
	 * @param sqlName the sqlName to set
	 */
	public void setSqlName(String sqlName) {
		this.sqlName = sqlName;
	}

	/**
	 * @return the pk
	 */
	public boolean isPk() {
		return pk;
	}

	/**
	 * @param pk the pk to set
	 */
	public void setPk(boolean pk) {
		this.pk = pk;
	}

	/**
	 * @return the size
	 */
	public int getSize() {
		return size;
	}

	/**
	 * @param size the size to set
	 */
	public void setSize(int size) {
		this.size = size;
	}

	/**
	 * @return the decimalDigits
	 */
	public int getDecimalDigits() {
		return decimalDigits;
	}

	/**
	 * @param decimalDigits the decimalDigits to set
	 */
	public void setDecimalDigits(int decimalDigits) {
		this.decimalDigits = decimalDigits;
	}

	/**
	 * @return the nullable
	 */
	public boolean isNullable() {
		return nullable;
	}

	/**
	 * @param nullable the nullable to set
	 */
	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}

	/**
	 * @return the indexed
	 */
	public boolean isIndexed() {
		return indexed;
	}

	/**
	 * @param indexed the indexed to set
	 */
	public void setIndexed(boolean indexed) {
		this.indexed = indexed;
	}

	/**
	 * @return the unique
	 */
	public boolean isUnique() {
		return unique;
	}

	/**
	 * @param unique the unique to set
	 */
	public void setUnique(boolean unique) {
		this.unique = unique;
	}

	/**
	 * @return the defaultValue
	 */
	public String getDefaultValue() {
		return defaultValue;
	}

	/**
	 * @param defaultValue the defaultValue to set
	 */
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	/**
	 * @return the remarks
	 */
	public String getRemarks() {
		return remarks;
	}

	/**
	 * @param remarks the remarks to set
	 */
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	/**
	 * @return the autoIncrement
	 */
	public boolean isAutoIncrement() {
		return autoIncrement;
	}

	/**
	 * @param autoIncrement the autoIncrement to set
	 */
	public void setAutoIncrement(boolean autoIncrement) {
		this.autoIncrement = autoIncrement;
	}

	/**
	 * @return the generatedColumn
	 */
	public boolean isGeneratedColumn() {
		return generatedColumn;
	}

	/**
	 * @param generatedColumn the generatedColumn to set
	 */
	public void setGeneratedColumn(boolean generatedColumn) {
		this.generatedColumn = generatedColumn;
	}

	/**
	 * @return the fullJavaType
	 */
	public String getFullJavaType() {
		return fullJavaType;
	}

	/**
	 * @param fullJavaType the fullJavaType to set
	 */
	public void setFullJavaType(String fullJavaType) {
		this.fullJavaType = fullJavaType;
	}

	/**
	 * @return the javaProperty
	 */
	public String getJavaProperty() {
		return javaProperty;
	}

	/**
	 * @param javaProperty the javaProperty to set
	 */
	public void setJavaProperty(String javaProperty) {
		this.javaProperty = javaProperty;
	}
	
	@JsonIgnore
	public String getSimpleJavaType() {
		return StringTools.getJavaClassSimpleName(this.fullJavaType);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "DatabaseColumn [sqlType=" + sqlType + ", sqlTypeName=" + sqlTypeName + ", sqlName=" + sqlName + ", pk="
				+ pk + ", size=" + size + ", decimalDigits=" + decimalDigits + ", nullable=" + nullable + ", indexed="
				+ indexed + ", unique=" + unique + ", defaultValue=" + defaultValue + ", remarks=" + remarks
				+ ", autoIncrement=" + autoIncrement + ", generatedColumn=" + generatedColumn + ", fullJavaType="
				+ fullJavaType + ", javaProperty=" + javaProperty + "]";
	}
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((sqlName == null) ? 0 : sqlName.hashCode());
        result = prime * result + ((table == null) ? 0 : table.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        DatabaseColumn other = (DatabaseColumn) obj;
        if (sqlName == null) {
            if (other.sqlName != null)
                return false;
        } else if (!sqlName.equals(other.sqlName))
            return false;
        if (table == null) {
            if (other.table != null)
                return false;
        } else if (!table.equals(other.table))
            return false;
        return true;
    }
	
	
	

}
